package com.zf.yichat.config.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.util.*;

import com.zf.yichat.utils.common.HttpUtils;
import com.zf.yichat.utils.common.N3d;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpResponse;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelReaderUtils {

    public static void main(String[] args) {
        try {
            readExcel();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static List<Long> readExcel () throws IOException {

        String filePath = "G:\\user.xlsx";

        List<Long> resultList = new ArrayList<>();

        FileInputStream inputStream = new FileInputStream (filePath);
        Workbook workbook = new XSSFWorkbook (inputStream);

        Sheet sheet = workbook.getSheetAt (0);
        Iterator<Row> rowIterator = sheet.iterator ();

        while (rowIterator.hasNext ()) {
            Row row = rowIterator.next ();
            Iterator<Cell> cellIterator = row.cellIterator ();
            while (cellIterator.hasNext ()) {
                Cell cell = cellIterator.next ();
                String cellValue = "";

                if (cell.getCellType () == Cell.CELL_TYPE_NUMERIC) {
                    cell.setCellType (Cell.CELL_TYPE_STRING); // 将数字类型的单元格设置为字符串类型
                    cellValue = cell.getStringCellValue ();
                } else if (cell.getCellType () == Cell.CELL_TYPE_STRING) {
                    cellValue = cell.getStringCellValue ();
                }
                long aLong = Long.parseLong(cellValue);
                resultList.add (aLong);
            }
        }

        workbook.close ();
        inputStream.close ();

//        for (Long id : resultList) {
//            deleteRongYunUser(id);
//        }
        return resultList;
    }



    public static String hexSHA1(String value) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.update(value.getBytes("utf-8"));
            byte[] digest = md.digest();
            return byteToHexString(digest);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }

    }
    public static String byteToHexString(byte[] bytes) {
        return String.valueOf(Hex.encodeHex(bytes));
    }
}
